package com.taotao.wjspringboot.config;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * @author wangjin
 * @title: KtWebApplicationInitaizer
 * @projectName wj-springboot
 * @description:
 * @date 2021/10/23 16:59
 */
public class KtWebApplicationInitaizer implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        //web.xml拦截所所有的请求
        //1.springmvc 容器
        AnnotationConfigWebApplicationContext web = new AnnotationConfigWebApplicationContext();
        //注册SpringMVC注册类
        web.register(SpringMVCConfig.class);
        //3.

        ServletRegistration.Dynamic dynamic = servletContext.addServlet("dispather", new DispatcherServlet(web));
        //4,填写url映射地址
        dynamic.addMapping("/");
        dynamic.setLoadOnStartup(1);//优先级越高越早加载


    }
}
